<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace app\store\controller;

class IndexStore extends \app\ApiRest
{
    public function __construct(\think\App $app)
    {
        parent::__construct($app);
    }
    public function storeCateList()
    {
        $input = $this->_param;
        $dis = ["status" => 1, "uniacid" => $this->_uniacid];
        $cate_model = new \app\store\model\StoreCate();
        $data = $cate_model->where($dis)->order("top desc,id desc")->field("id,title,cover")->select()->toArray();
        return $this->success($data);
    }
    public function storeList()
    {
        $input = $this->_param;
        $dis[] = ["a.uniacid", "=", $this->_uniacid];
        $dis[] = ["a.status", "=", 1];
        $dis[] = ["b.status", "=", 1];
        $dis[] = ["b.agent_coach_auth", "=", 1];
        if(!empty($input["title"])) {
            $dis[] = ["a.title", "like", "%" . $input["title"] . "%"];
        }
        if(!empty($input["cate_id"])) {
            $dis[] = ["c.cate_id", "=", $input["cate_id"]];
        }
        $lat = !empty($input["lat"]) ? $input["lat"] : 0;
        $lng = !empty($input["lng"]) ? $input["lng"] : 0;
        $alh = "ACOS(SIN((" . $lat . " * 3.1415) / 180 ) *SIN((a.lat * 3.1415) / 180 ) +COS((" . $lat . " * 3.1415) / 180 ) * COS((a.lat * 3.1415) / 180 ) *COS((" . $lng . " * 3.1415) / 180 - (a.lng * 3.1415) / 180 ) ) * 6378.137*1000 as distance";
        $store_model = new \app\store\model\StoreList();
        $data = $store_model->indexDataListV2($dis, $alh);
        if(!empty($data["data"])) {
            foreach ($data["data"] as &$v) {
                $v["work_status"] = $store_model->workStatus($v);
                $v["distance"] = distance_text($v["distance"]);
            }
        }
        return $this->success($data);
    }
    public function storeInfo()
    {
        $input = $this->_param;
        $store_model = new \app\store\model\StoreList();
        $service_model = new \app\massage\model\Service();
        $coach_model = new \app\massage\model\Coach();
        $dis = ["id" => $input["id"]];
        $data["info"] = $store_model->dataInfo($dis);
        $where = $where1 = [];
        if($this->is_app == 0 && getConfigSetting($this->_uniacid, "shield_massage") == 1) {
            $where[] = ["a.industry_type", "<>", 1];
            $where1[] = ["industry_type", "<>", 1];
        }
        $data["service_list"] = $service_model->getStoreService($input["id"], $where);
        $shield_coach = $coach_model->getShieldCoach($this->getUserId());
        $store_coach_id = $store_model->getStoreCoachId($input["id"]);
        $coach_format = getConfigSetting($this->_uniacid, "coach_format");
        if(in_array($coach_format, [1, 3])) {
            $data["coach_list"] = $coach_model->where($where1)->where(["store_id" => $input["id"], "status" => 2, "auth_status" => 2, "is_work" => 1])->where("id", "in", $store_coach_id)->where("id", "not in", $shield_coach)->field("id,coach_name,work_img,city_id")->order("id desc")->limit(10)->select()->toArray();
        } else {
            $data["coach_list"] = $coach_model->where($where1)->where(["store_id" => $input["id"], "status" => 2, "auth_status" => 2])->where("id", "in", $store_coach_id)->where("id", "not in", $shield_coach)->field("id,coach_name,work_img,city_id")->order("id desc")->limit(10)->select()->toArray();
        }
        $member_service = new \app\member\model\Service();
        $user_member = $member_service->getUserMember($this->_uniacid, $this->getUserId());
        if(!empty($data["service_list"])) {
            foreach ($data["service_list"] as $k => &$v) {
                $v["member_service"] = $user_member["member_auth"] == 1 ? $v["member_service"] : 0;
                $v["member_info"] = $member_service->getServiceMember($v["id"], $user_member["member_level"], $v["member_service"]);
            }
        }
        $data["service_list"] = giveMemberPrice($this->_uniacid, $data["service_list"]);
        return $this->success($data);
    }
    public function storeServiceList()
    {
        $input = $this->_param;
        $service_model = new \app\massage\model\Service();
        $position_model = new \app\massage\model\ServicePositionConnect();
        $where = [];
        if($this->is_app == 0 && getConfigSetting($this->_uniacid, "shield_massage") == 1) {
            $where[] = ["c.industry_type", "<>", 1];
        }
        $data = $service_model->getStoreServicePage($input["id"], $where);
        $member_service = new \app\member\model\Service();
        $user_member = $member_service->getUserMember($this->_uniacid, $this->getUserId());
        if(!empty($data["data"])) {
            foreach ($data["data"] as $k => &$v) {
                $v["position_title"] = $position_model->positionTitle($v["id"]);
                $v["member_service"] = $user_member["member_auth"] == 1 ? $v["member_service"] : 0;
                $v["member_info"] = $member_service->getServiceMember($v["id"], $user_member["member_level"], $v["member_service"]);
            }
        }
        $data["data"] = giveMemberPrice($this->_uniacid, $data["data"]);
        return $this->success($data);
    }
    public function commentList()
    {
        $input = $this->_param;
        $comment_model = new \app\massage\model\Comment();
        $coach_model = new \app\massage\model\Coach();
        $store_model = new \app\store\model\StoreList();
        $shield_coach = $coach_model->getShieldCoach($this->getUserId());
        $store_coach_id = $store_model->getStoreCoachId($input["id"]);
        $coach_list = $coach_model->where(["store_id" => $input["id"], "status" => 2, "is_work" => 1])->where("id", "in", $store_coach_id)->where("id", "not in", $shield_coach)->column("id");
        $dis[] = ["a.status", "=", 1];
        $dis[] = ["a.coach_id", "in", $coach_list];
        $data = $comment_model->dataList($dis);
        $config_model = new \app\massage\model\Config();
        $anonymous_evaluate = $config_model->where(["uniacid" => $this->_uniacid])->value("anonymous_evaluate");
        if(!empty($data["data"])) {
            foreach ($data["data"] as &$v) {
                $v["create_time"] = date("Y-m-d H:i:s", $v["create_time"]);
                if($anonymous_evaluate == 1 || $v["user_id"] == 0) {
                    $v["nickName"] = "匿名用户";
                    $v["avatarUrl"] = "https://lbqny.migugu.com/admin/farm/default-user.png";
                }
            }
        }
        return $this->success($data);
    }
}

?>